<?php

namespace Biz\service\advertisement\apiModule;

use Doraemon\model\Position\PositionExtend;
use Doraemon\service\search\PeopleSearch;
use Doraemon\tools\StatSign;
use Doraemon\service\statSign\Basic as svcStatSign;

class KeywordSearch extends BaseModule
{
    const FORMAT_HIT = 'formatPosHitAll';

    public function format($hits, $uid, $userProfileExt, $statSignExt)
    {
        $list = [];
        if ($hits) {
            $highlight = $hits[1] ?? [];
            $normal = $hits[0] ?? [];
            foreach ($highlight as $hit) {
                $list[] = [
                    'id' => (int)$hit['id'],
                    'name' => $hit['ext']['key_word'],
                    'type' => $hit['pos'],
                    'link' => $this->generateLink($hit['link_type'], $hit['link_params']),
                    'statSign' => $this->statSign($hit, $statSignExt)
                ];
            }

            foreach ($normal as $hit) {
                $list[] = [
                    'id' => (int)$hit['id'],
                    'name' => $hit['ext']['key_word'],
                    'type' => $hit['pos'],
                    'link' => $this->generateLink($hit['link_type'], $hit['link_params']),
                    'statSign' => $this->statSign($hit, $statSignExt)
                ];
            }
        }

        return [
            'rows' => $list,
        ];
    }

    public function uniquePos($v) : string
    {
        return $v['ext']['key_word'] ?? '';
    }
}